package com.tiankun.eurekaticket.controller;


import com.tiankun.eurekaticket.pojo.Ticket;
import com.tiankun.eurekaticket.service.TicketService;
import com.tiankun.eurekaticket.util.JsonResult;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author liaopeng
 * @Date 2020/11/11 10:27
 * @Version 1.0
 **/

@RestController
@RequestMapping("/ticket")
@Api(value = "后台控制器",tags = "优惠券接口的api")
public class TicketController {

    @RequestMapping("hello")
    @ResponseBody
    public String hello() {
        return "success";
    }

    @Resource
    TicketService ticketService;



    @PostMapping("/add")
    @ApiOperation(value = "新增优惠券的接口",notes = "新增优惠券的信息",httpMethod = "post")
    public Map add(@RequestBody @ApiParam
            (name = "ticket",value = "优惠券的pojo信息",required = true) Ticket ticket){
        Integer insert = ticketService.insert(ticket);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");
        return jsonResult.getValues();
    }

    @PostMapping("/page")
    @ApiOperation(value = "后台查询所有设计的优惠券列表的接口",notes = "获取所有领取优惠券列表,参数为店铺id",httpMethod = "post",response = String.class)
    @ApiImplicitParam(name = "shopid",value = "店铺的id",required = true,dataType = "int",paramType = "path")
    public Map getTicketList(@RequestParam("shopid")Integer shopid){
        List<Map<String, Object>> allticketList = ticketService.findAllticketList(shopid);
        JsonResult jsonResult = new JsonResult();
            jsonResult.setMsg("查询成功");
            jsonResult.setCode("1");
            jsonResult.setData(allticketList);
        return jsonResult.getValues();
    }

    @PostMapping("/userlist")
    @ApiOperation(value = "后台查询用户领取优惠券列表的接口",notes = "获取所有领取优惠券列表",httpMethod = "post",response = String.class)
    @ApiImplicitParam(name = "shopid",value = "店铺的id",required = true,dataType = "int",paramType = "path")
    public Map getTicketUserList(@RequestParam("shopid")Integer shopid){
        List<Map<String, Object>> userList = ticketService.userList(shopid);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("1");
        jsonResult.setData(userList);
        return jsonResult.getValues();
    }

    @PostMapping("/find")
    @ApiOperation(value = "后台查询单张优惠券信息的接口",notes = "获取单张优惠券的数据",httpMethod = "post",response = String.class)
    @ApiImplicitParam(name = "id",value = "优惠券的id",required = true,dataType = "int",paramType = "path")
    public Map getTicket(@RequestParam("id") Integer id){
        Ticket ticket = ticketService.find(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("1");
        jsonResult.setData(ticket);
        return jsonResult.getValues();
    }

    @PostMapping("/like")
    @ApiOperation(value = "后台模糊查询已设计优惠券列表的接口",notes = "获取模糊查询到的优惠券列表的数据",httpMethod = "post",response = String.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shopid",value = "店铺id",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name = "name",value = "优惠券名称",required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "random",value = "优惠券流水号",required = true,dataType = "String",paramType = "query")
    })
    public Map findTicketByLike(@RequestParam("shopid") Integer shopid,@RequestParam("random") String random,@RequestParam("name") String name) {
        List<Map<String, Object>> allticketListByLike = ticketService.findAllticketListByLike(shopid, random, name);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("1");
        jsonResult.setData(allticketListByLike);
        return jsonResult.getValues();
    }

    @PostMapping("/updateState")
    @ApiOperation(value = "修改优惠券上下架的接口",notes = "获取所有领取优惠券列表，无需参数",httpMethod = "post",response = String.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "优惠券id",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name = "state",value = "优惠券上下架状态",required = true,dataType = "Integer",paramType = "query")
    })
    public Map updateState(@RequestParam("id") Integer id,@RequestParam("state") Integer state) {
        Integer integer = ticketService.update(id, state);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("修改成功");
        jsonResult.setCode("1");
        return jsonResult.getValues();
    }

    @PostMapping("/userListLike")
    @ApiOperation(value = "后台模糊查询用户领取优惠券列表的接口",notes = "获取模糊查询到的优惠券列表的数据",httpMethod = "post",response = String.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "random",value = "优惠券流水号",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name = "shopid",value = "优惠券名称",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name = "name",value = "优惠券名称",required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "usestate",value = "优惠券使用状态",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name = "userName",value = "领取人姓名",required = true,dataType = "String",paramType = "query")
    })
    public Map findUserListByLike(@RequestParam("shopid") Integer shopid,@RequestParam("name") String name,@RequestParam("usestate") Integer usestate,@RequestParam("random") String random,@RequestParam("userName") String userName) {
        List<Map<String, Object>> userListLike = ticketService.userListLike(shopid,name,usestate,random,userName);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("1");
        jsonResult.setData(userListLike);
        return jsonResult.getValues();
    }

    @PostMapping("/findPutawayticketList")
    @ApiOperation(value = "前台店铺领取优惠券列表的接口",notes = "获取所有领取优惠券列表",httpMethod = "post",response = String.class)
    @ApiImplicitParam(name = "shopid",value = "店铺的id",required = true,dataType = "int",paramType = "path")
    public Map findPutawayticketList(@RequestParam("shopid")Integer shopid){
        List<Map<String, Object>> putawayticketList = ticketService.findPutawayticketList(shopid);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("1");
        jsonResult.setData(putawayticketList);
        return jsonResult.getValues();
    }

}
